package com.eobjectsoft.etranslator.engine;

/**
 * list all the translation mapping supported by google translate engine so far.
 *
 */
public final class TranslateMode
{

    public static final TranslateMode CHINESECN2ENGLISH;
    public static final TranslateMode CHINESETW2ENGLISH;
    public static final TranslateMode CHINESECN2CHINESETW;
    public static final TranslateMode CHINESETW2CHINESECN;
    public static final TranslateMode ENGLISH2CHINESECN;
    public static final TranslateMode ENGLISH2CHINESETW;
    public static final TranslateMode ENGLSISH2FRENCH;
    public static final TranslateMode ENGLISH2GERMAN;
    public static final TranslateMode ENGLISH2ITALIAN;
    public static final TranslateMode ENGLISH2JAPANESE;
    public static final TranslateMode ENGLISH2KOREAN;
    public static final TranslateMode ENGLISH2PORTUGUESE;
    public static final TranslateMode ENGLISH2RUSSIAN;
    public static final TranslateMode ENGLISH2SPANISH;
    public static final TranslateMode FRANCH2ENGLISH;
    public static final TranslateMode FRENCH2GERMAN;
    public static final TranslateMode GERMAN2ENGLISH;
    public static final TranslateMode GERMAN2FRANCH;
    public static final TranslateMode ITALIAN2ENGLISH;
    public static final TranslateMode JAPANESE2ENGLISH;
    public static final TranslateMode KOREAN2ENGLISH;
    public static final TranslateMode PORTUGUESE2ENGLISH;
    public static final TranslateMode RUSSIAN2ENGLISH;
    public static final TranslateMode SPANISH2ENGLISH;
    public static TranslateMode modes[];
    private final String langpair;

    static 
    {
        CHINESECN2ENGLISH = new TranslateMode("zh-CN|en");
        CHINESETW2ENGLISH = new TranslateMode("zh-TW|en");
        CHINESECN2CHINESETW = new TranslateMode("zh-CN|zh-TW");
        CHINESETW2CHINESECN = new TranslateMode("zh-TW|zh-CN");
        ENGLISH2CHINESECN = new TranslateMode("en|zh-CN");
        ENGLISH2CHINESETW = new TranslateMode("en|zh-TW");
        ENGLSISH2FRENCH = new TranslateMode("en|fr");
        ENGLISH2GERMAN = new TranslateMode("en|de");
        ENGLISH2ITALIAN = new TranslateMode("en|it");
        ENGLISH2JAPANESE = new TranslateMode("en|ja");
        ENGLISH2KOREAN = new TranslateMode("en|ko");
        ENGLISH2PORTUGUESE = new TranslateMode("en|pt");
        ENGLISH2RUSSIAN = new TranslateMode("en|ru");
        ENGLISH2SPANISH = new TranslateMode("en|es");
        FRANCH2ENGLISH = new TranslateMode("fr|en");
        FRENCH2GERMAN = new TranslateMode("fr|de");
        GERMAN2ENGLISH = new TranslateMode("de|en");
        GERMAN2FRANCH = new TranslateMode("de|fr");
        ITALIAN2ENGLISH = new TranslateMode("it|en");
        JAPANESE2ENGLISH = new TranslateMode("ja|en");
        KOREAN2ENGLISH = new TranslateMode("ko|en");
        PORTUGUESE2ENGLISH = new TranslateMode("pt|en");
        RUSSIAN2ENGLISH = new TranslateMode("ru|en");
        SPANISH2ENGLISH = new TranslateMode("es|en");
        modes = (new TranslateMode[] {
            CHINESECN2ENGLISH, CHINESETW2ENGLISH, CHINESECN2CHINESETW, CHINESETW2CHINESECN, ENGLISH2CHINESECN, ENGLISH2CHINESETW, ENGLSISH2FRENCH, ENGLISH2GERMAN, ENGLISH2ITALIAN, ENGLISH2ITALIAN, 
            ENGLISH2JAPANESE, ENGLISH2KOREAN, ENGLISH2PORTUGUESE, ENGLISH2RUSSIAN, ENGLISH2SPANISH, FRANCH2ENGLISH, FRENCH2GERMAN, GERMAN2ENGLISH, GERMAN2FRANCH, ITALIAN2ENGLISH, 
            JAPANESE2ENGLISH, KOREAN2ENGLISH, KOREAN2ENGLISH, PORTUGUESE2ENGLISH, RUSSIAN2ENGLISH, SPANISH2ENGLISH
        });
    }
    
    public String toString()
    {
        return langpair;
    }

    protected TranslateMode(String mode)
    {
        langpair = mode;
    }

    public static TranslateMode getTranslateMode(String sourceLang, String targetLang)
    {
        String value = sourceLang + "|" + targetLang;
        for(int i = 0; i < modes.length; i++)
            if(modes[i].toString().equals(value))
                return modes[i];

        return null;
    }

    public String getFromLanguage()
    {
        return langpair.substring(0, langpair.indexOf("|"));
    }

    public String getTargetLanguage()
    {
        return langpair.substring(langpair.indexOf("|") + 1);
    }

}
